package com.yh.csx.demo.controller;
import com.yh.csx.demo.service.MQExampleSerivice;
import com.yh.csx.demo.service.MessageExampleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api("MQ测试")
@RestController
@RequestMapping("/example")
public class MQController {
	@Autowired
	private MQExampleSerivice mqExampleSerivice;
	@Autowired
	private MessageExampleService messageExampleService;

	@ApiOperation("消费消息")
	@GetMapping("/registerConsumer")
	public void registerConsumer() {
		mqExampleSerivice.registerConsumer();
	}

	@ApiOperation("发送消息")
	@GetMapping("/sendMessage")
	public String sendMessage(Integer size) {

		ExecutorService pool = Executors.newFixedThreadPool(1);		
			pool.submit(() -> {
				while (true) {
					try {
						mqExampleSerivice.sendMessage(size==null||size<1?0:size);
						Thread.sleep(10000);
					}catch(Exception e) {
						
					}
				}
			});		
		return "";
	}

	@GetMapping("/sendSms")
	public void sendSms() {
		messageExampleService.sendSms(0, "1122");
	}
}
